package experiment3.shudu001.activity;


import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import experiment3.shudu001.R;
import experiment3.shudu001.models.PrefsManager;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.OvershootInterpolator;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button newGameButton = (Button) findViewById(R.id.newGameButton);
        Button continueButton = (Button) findViewById(R.id.continueButton);
        Button settingsButton = (Button) findViewById(R.id.settingsButton);
        Button statisticsButton = (Button) findViewById(R.id.statisticsButton);
        Button helpButton = (Button) findViewById(R.id.helpButton);
        TextView title = (TextView)findViewById(R.id.titleTextView);


        ObjectAnimator scaleX = ObjectAnimator.ofFloat(title, "scaleX", 0.8f, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(title, "scaleY", 0.8f, 1f);

        AnimatorSet animSet = new AnimatorSet();
        animSet.playTogether(scaleX, scaleY);
        animSet.setDuration(800);
        animSet.setInterpolator(new OvershootInterpolator());
        animSet.start();

        newGameButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, DifficultyActivity.class);
                startActivity(intent);
            }
        });

        continueButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 检查是否有保存的游戏
                if (PrefsManager.hasSavedGame(MainActivity.this)) {
                    Intent intent = new Intent(MainActivity.this, GameActivity.class);
                    intent.putExtra("loadSaved", true);
                    startActivity(intent);
                }
            }
        });

        settingsButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
                startActivity(intent);
            }
        });

        statisticsButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, StatisticsActivity.class);
                startActivity(intent);
            }
        });

        helpButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, HelpActivity.class);
                startActivity(intent);
            }
        });
    }
}